﻿using System;
using Jxym.Common.JSON;
using Newtonsoft.Json;
using Jxym.DBUtility;
using Jxym.wlkc2011.Module.Default.model;
using Newtonsoft.Json.Converters;
using System.Collections.Generic;

namespace Jxym.wlkc2011.Module.Default.server.Files
{
    public partial class FilesList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                try
                {
                    int startIndex = 0, limit = 0, depmetId = 0;
                    if (Request.Params["start"] != null) startIndex = Convert.ToInt32(Request.Params["start"]);
                    if (Request.Params["limit"] != null) limit = Convert.ToInt32(Request.Params["limit"]);
                    if (Request.Params["depmetId"] != null) depmetId = Convert.ToInt32(Request.Params["depmetId"]);
                    if (Request.Params["limit"] != null && Request.Params["start"] != null)
                    {
                        if (depmetId != 0 && limit != 0)
                        {
                            MsSqlDal<model.Files> list = new MsSqlDal<model.Files>();
                            IList<model.Files> List = list.GetPageList("ParentID=" + depmetId, null, Convert.ToInt32(Request.Params["start"]), Convert.ToInt32(Request.Params["limit"]));
                            IList<model.Files> nList = new List<model.Files>();
                            foreach (model.Files info in List)
                            {
                                info.CreateID = MyGet.GetUserInfoByID(info.CreateID).Name;
                                nList.Add(info);
                            }
                            PageBean pb = new PageBean();
                            pb.Count = list.GetPageCount("ParentID=" + depmetId, null);
                            pb.List = nList;
                            Response.Write(JsonConvert.SerializeObject(pb, new JavaScriptDateTimeConverter()));
                        }
                        else
                        {
                            MsSqlDal<model.Files> list = new MsSqlDal<model.Files>();
                            IList<model.Files> List = list.GetPageList("", null, Convert.ToInt32(Request.Params["start"]), Convert.ToInt32(Request.Params["limit"]));
                            IList<model.Files> nList = new List<model.Files>();
                            foreach (model.Files info in List)
                            {
                                info.CreateID = MyGet.GetUserInfoByID(info.CreateID).Name;
                                nList.Add(info);
                            }
                            PageBean pb = new PageBean();
                            pb.Count = list.GetPageCount("ParentID=" + depmetId, null);
                            pb.List = nList;
                            Response.Write(JsonConvert.SerializeObject(pb, new JavaScriptDateTimeConverter()));
                        }
                    }
                    else
                    {
                        Response.Write("{List:[],Count:0}");
                    }
                }
                catch (Exception)
                {
                    Response.Write("{List:[],Count:0}");
                }
            }
        }
    }
}